package com.todo.strategy.online.application.api.controller;

import com.todo.common.common.entity.response.BizResponse;
import com.todo.strategy.online.application.service.pipeline.PlanRelationPipelineService;
import com.todo.strategy.online.service.api.pipeline.PlanRelationPipelineApi;
import com.todo.strategy.online.service.api.pipeline.request.InsertPlanRelationRequest;
import com.todo.strategy.online.service.api.pipeline.request.RemovePlanRelationRequest;
import com.todo.strategy.online.service.api.pipeline.request.UpdatePlanRelationRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2025/3/1 17:23
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/api/pipeline/planRelation")
@Tag(name = "服务端-计划关联同步接口", description = "服务端-计划关联同步接口")
public class PlanRelationPipelineApiController implements PlanRelationPipelineApi {

    @Resource
    private PlanRelationPipelineService planRelationPipelineService;

    @Override
    @Operation(summary = "插入计划关联")
    @PostMapping("/insertPlanRelation")
    public BizResponse<Boolean> insertPlanRelation(@RequestBody InsertPlanRelationRequest request) {
        if (request == null || !request.isCheck()) {
            return BizResponse.paramError();
        }
        Boolean result = planRelationPipelineService.insertPlanRelation(request.getOriginData());
        return BizResponse.success(result);
    }

    @Override
    @Operation(summary = "更新计划关联")
    @PostMapping("/updatePlanRelation")
    public BizResponse<Boolean> updatePlanRelation(@RequestBody UpdatePlanRelationRequest request) {
        if (request == null || !request.isCheck()) {
            return BizResponse.paramError();
        }
        Boolean result = planRelationPipelineService.updatePlanRelation(request.getBusinessId(), request.getOriginData());
        return BizResponse.success(result);
    }

    @Override
    @Operation(summary = "删除计划关联")
    @PostMapping("/removePlanRelation")
    public BizResponse<Boolean> removePlanRelation(@RequestBody RemovePlanRelationRequest request) {
        if (request == null || !request.isCheck()) {
            return BizResponse.paramError();
        }
        Boolean result = planRelationPipelineService.removePlanRelation(request.getBusinessId());
        return BizResponse.success(result);
    }
}
